package com.yfp.client.controller;

import com.yfp.client.domain.AiPresetQuestion;
import com.yfp.client.domain.AiPrompt;
import com.yfp.client.domain.vo.AiModelServiceInfoVO;
import com.yfp.client.service.AiModelServiceService;
import com.yfp.client.service.AiPresetQuestionService;
import com.yfp.client.service.AiPromptService;
import com.yfp.client.util.Response;
import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequestMapping("/client/ai")
@Tag(name = "AI")
public class AIModelController extends BaseController {

    @Resource
    private AiModelServiceService aiModelServiceService;
    @Resource
    private AiPresetQuestionService aiPresetQuestionService;
    @Resource
    private AiPromptService aiPromptService;

    @GetMapping("/prompt")
    @Operation(summary = "提示词设置-提示词详情")
    public Response<AiPrompt> searchAiPrompt() {
        AiPrompt aiPrompt = aiPromptService.searchAiPrompt();
        return Response.success(aiPrompt);
    }

    @GetMapping("/question")
    @Operation(summary = "预设问题-问题详情")
    public Response<List<AiPresetQuestion>> searchAiPresetQuestion() {
        List<AiPresetQuestion> aiPresetQuestions = aiPresetQuestionService.searchAiPresetQuestion();
        return Response.success(aiPresetQuestions);
    }

    @GetMapping("/model")
    @Operation(summary = "模型-模型详情")
    public R<AiModelServiceInfoVO> searchActiveModel() {
        AiModelServiceInfoVO aiModelServiceInfoVO = aiModelServiceService.searchActiveModel();
        return R.ok(aiModelServiceInfoVO);
    }

    @GetMapping("/model/invoke/chat/call")
    @Operation(summary = "模型-调用-非流式")
    public R<String> chatCall(String message) {
        String content = aiModelServiceService.chatCall(message);
        return R.ok(content);
    }

    @GetMapping(value = "/model/invoke/chat/stream")
    // @GetMapping(value = "/model/invoke/chat/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @Operation(summary = "模型-调用-流式")
    public Flux<String> chatStream(String message) {
        Flux<String> content = aiModelServiceService.chatStream(message);
        return content;
    }
}
